<html>
<h1> Calculator </h1>
<body>
</br>
<form method="GET">
<input type="text" name="calc"> <input type="submit" value="Calculate!">
</form>

<?php
error_reporting(0);
$expr = $_GET["calc"];
if($expr){
	echo "</br>";
	echo "<h2> Result: </h2>";
	$nmatch = preg_match("#^((-?\d+(\.\d*)?)\s*[\+\-\*/])*\s*-?\d+(\.\d*)?#i", $expr);
	if($nmatch == 1)
	{
		for($i = 0; $i < count($matches); $i++)
			echo $matches[$i]."</br>";
		if(eval("\$ans= $expr; return true;"))
		echo $expr." = ".$ans."</br>";
		else
		{
			echo $expr." is invalid";
		}
	}
	else
	{
		echo $expr." is an invalid expression";
	}
}
?>
</body>
</html>